package com.neu.service;

import com.github.pagehelper.PageHelper;
import com.neu.dao.ShoppingAdMapper;
import com.neu.domain.ShoppingAd;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ShoppingAdService {

    @Resource
    private ShoppingAdMapper shoppingAdMapper;

    public List<ShoppingAd> querySelective(String name, String content, Integer page, Integer limit, String sort, String order) {
        try{
            int pagetIndex =Integer.valueOf(page);
            int pageSizeInt=Integer.valueOf(limit);
            PageHelper.startPage(pagetIndex,pageSizeInt);
            return shoppingAdMapper.selectByExample(name,content,page,limit,sort,order);

        }catch (Exception ex){
            ex.printStackTrace();
        }

        return null;
    }

    public int deleteById(Integer id) {
        try{
            int flag=shoppingAdMapper.logicalDeleteByPrimaryKey(id);
            return flag;

        }catch (Exception ex){
            ex.printStackTrace();
        }
        return 0;
    }

    public int add(ShoppingAd ad) {
        try{
            return shoppingAdMapper.insertSelective(ad);

        }catch (Exception ex){
            ex.printStackTrace();
        }
        return 0;
    }

    public int updateById(ShoppingAd ad) {
        try{
            return shoppingAdMapper.updateByPrimaryKeySelective(ad);

        }catch (Exception ex){
            ex.printStackTrace();
        }

        return 0;
    }
}
